<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Account_bank_model extends CI_Model {
	
	function __construct(){
        parent::__construct();
    }
    
    
	function arrays($key){
    	$data = array(
    		'var_account_bank'  => array(
										'1'=>'中国银行',
										'2'=>'工商银行',
										'3'=>'农业银行',
										'4'=>'交通银行',
										'5'=>'广发银行',
										'6'=>'深发银行',
										'7'=>'建设银行',
										'8'=>'上海浦发银行',
										'9'=>'浙江泰隆商业银行',
										'10'=>'招商银行',
										'11'=>'邮政储蓄银行',
										'12'=>'民生银行',
										'13'=>'兴业银行',
										'14'=>'广东发展银行',
										'15'=>'东莞银行',
										'16'=>'深圳发展银行',
										'17'=>'中信银行',
										'18'=>'华夏银行',
										'19'=>'中国光大银行',
										'20'=>'北京银行',
										'21'=>'上海银行',
										'22'=>'天津银行',
										'23'=>'大连银行',
										'24'=>'杭州银行',
										'25'=>'宁波银行',
										'26'=>'厦门银行',
										'27'=>'广州银行',
										'28'=>'平安银行',
										'29'=>'浙商银行',
										'30'=>'上海农村商业银行',
										'31'=>'重庆银行',
										'32'=>'江苏银行',
						),
				'var_account_cash_status' 	=> array("0"=>"申请", "1"=>"审核通过", "2"=>"审核拒绝", "3"=>"用户取消", "4"=>"到账"),
				'var_user_loan' 	=> array("0"=>"投资客", "1"=>"借款户"),
    	);
    	
    	if($key && isset($data[$key])){
    		return $data[$key];
    	}else{
    		return array();
    	}
    }
    
    function add($data = array()){
		if(isset($data['user_id'])){
			$this->db->insert('zjy_account_bank', $data);
			return $this->db->insert_id();
		}else{
			return false;
		}
	}
    
    function get_by_uid($user_id){
		$key = 'zjy_account_bank_' . $user_id;
		$this->mycache->delete($key);//@todo
		$row = $this->mycache->get_array($key);
		if($row == false){
			$this->db->where('user_id',$user_id);
			$query = $this->db->get('zjy_account_bank');
			$row = $query->row_array();
			if($row){
				$this->mycache->set_array($key,$row);
			}
		}
		return $row;
	}
	
	function get_one($where = array(),$select='*'){
		$this->db->select($select);
		if($where){
			$this->db->where($where);
		}
		$this->db->limit(1);
		$query = $this->db->get('zjy_account_bank');
		return $query->row_array();
	}
	
	function update($data = array(), $where = array()){
		if(isset($where['user_id'])){
			$this->db->where($where);
			$this->db->update('zjy_account_bank', $data);
			$res = $this->db->affected_rows();
			if($res > 0){
				$key = 'zjy_account_bank_'.$where['user_id'];
				$this->mycache->delete($key);
			}
			return $res;
		}else{
			return false;
		}
	}
    
}